// import proFetch from "../../../../../public/functions/project-fetch";
import { hrAjax as ajax, transRadio } from 'src/hrpub/common/utils/utils';
// import {transRadio} from "../../../../../../hrpub/common/utils/utils";
import { setFormAttrAndValue, chectFormAction } from '../../../../../public/functions/checkFormAction';
import { toast, cacheTools } from 'nc-lightapp-front';
import updateButtonStatus from './updateButtonStatus';

export default function getOneAgreementInfo() {
	const { editPk, agreementType, refreshFlag, json, orgVal } = this.state;
	const { form } = this.props;
	let appcode = '60110503',
		pageCode = '60110503p';
	if (!editPk) {
		this.setState(
			{
				pageFlag: 'list', //页面状态
				isEdit: false
			},
			() => {
				updateButtonStatus.call(this, orgVal, agreementType, false);
				if (this.state.pageFlag === 'list') {
					this.getMainTableData();
				}
			}
		);
		return;
	}
	// console.trace('aaaaa');
	return ajax({
		url: '/nccloud/hrcm/common/QueryDataCardAction.do',
		body: {
			agreementType: agreementType,
			pk_psndoc_sub: editPk,
			areaCode: 'agreementCard,' + agreementType + 'CardBefore,' + agreementType + 'CardAfter',
			pk_org: orgVal && orgVal.refpk ? orgVal.refpk : null,
			pageCode: pageCode,
			isContract: false
		}
	}).then((res) => {
		if (res.success) {
			let cardId = 'agreementCard';
			let attrMap = res.data && res.data.attrMap;
			let valueMap = res.data && res.data.valueMap;
			let extendParam = {
				pk_org: orgVal.refpk
			};
			this.refs.header.setCardPaginationVisible(true, editPk);
			if (!res.data) {
				//删除最后一条数据跳回列表界面
				this.setState(
					{
						pageFlag: 'list', //页面状态
						isEdit: false
					},
					() => {
						updateButtonStatus.call(this, orgVal, agreementType, false);
						if (this.state.pageFlag === 'list') {
							this.getMainTableData();
						}
					}
				);
				return;
			}else{
				this.setState({
					formrelation: res.data.formrelation[cardId]
				})
				let template = this.props.meta.getMeta();
				template.formrelation = res.data.formrelation;
				this.props.meta.setMeta(template)
			}
			setFormAttrAndValue(attrMap, valueMap, this.props, cardId, [ cardId ]);
			// chectFormAction('', cardId, this.props, [cardId], appcode, extendParam);
			if (res.data && res.data.data.agreementCard) {
				// let formData = transRadio(
				// 	res.data.data.agreementCard.rows,
				// 	true,
				// 	[ 'Y', 'N' ],
				// 	[ 'isrefer', 'ifprop', 'lastflag', 'isrefer_old', 'ifprop_old', 'lastflag_old' ],
				// 	[ json['cm6011-000057'], json['cm6011-000058'] ]
				// ); // 是-否
				let rows = res.data.data.agreementCard.rows
				form.setAllFormValue({[cardId]: {rows: rows}});
				// form.setAllFormValue({ [cardId]: formData });
			}
			// else {
			//     let formData = transRadio(res.data.data.traincontBaseCard.rows, true, ["Y", "N"], ['isrefer', 'ifprop', 'lastflag', 'isrefer_old', 'ifprop_old', 'lastflag_old'], [json['cm6011-000057'], json['cm6011-000058']]); // 是-否
			//     form.setAllFormValue({[cardId]: formData});
			// }
			if (refreshFlag) {
				toast({
					color: 'success',
					content: json['cm6011-000006'] //刷新成功！
				});
			}
		}
	});
}
